package cn.iocoder.yudao.module.member.convert.auth;

import cn.hutool.core.date.LocalDateTimeUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
import cn.iocoder.yudao.module.member.controller.admin.auth.vo.*;
import cn.iocoder.yudao.module.member.dal.dataobject.auth.MemberAuthDO;
import cn.iocoder.yudao.module.member.dal.dataobject.auth.MemberShopAuthDO;
import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantOnlyCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.tenantdetail.vo.TenantDetailCreateReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * 会员认证店铺 Convert
 *
 * @author 曹建伟
 */
@Mapper
public interface MemberShopAuthConvert {
    MemberShopAuthConvert INSTANCE = Mappers.getMapper(MemberShopAuthConvert.class);

    MemberShopAuthDO convert(MemberShopAuthCreateReqVO bean);

    MemberShopAuthRespVO convert(MemberShopAuthDO bean);

    List<MemberShopAuthRespVO> convertList(List<MemberShopAuthDO> list);

    PageResult<MemberShopAuthRespVO> convertPage(PageResult<MemberShopAuthDO> page);

    default MemberShopAuthDO convert(MemberShopAuthUpdateReqVO bean) {
        if ( bean == null ) {
            return null;
        }

        MemberShopAuthDO.MemberShopAuthDOBuilder shopAuthDO = MemberShopAuthDO.builder();

        shopAuthDO.id(bean.getId());
        shopAuthDO.shopName(bean.getShopName());
        shopAuthDO.memberId(bean.getMemberId());
        shopAuthDO.areaId(bean.getAreaId());
        shopAuthDO.address(bean.getAddress());
        shopAuthDO.description(bean.getDescription());
        shopAuthDO.picUrl(bean.getPicUrl());
        shopAuthDO.reason(bean.getReason());
        shopAuthDO.titleUrl(bean.getTitleUrl());
        shopAuthDO.status(bean.getStatus());
        shopAuthDO.size(bean.getSize());
        shopAuthDO.roomCount(bean.getRoomCount());
        shopAuthDO.jiushiCount(bean.getJiushiCount());
        shopAuthDO.videoUrl(bean.getVideoUrl());

        return shopAuthDO.build();
    }

    default TenantOnlyCreateReqVO convertTenantCreate(MemberShopAuthDO shopAuthDO, AdminUserDO adminUserDO){
        TenantOnlyCreateReqVO vo = new TenantOnlyCreateReqVO();

        vo.setAccountCount(99);
        vo.setContactMobile(adminUserDO.getMobile());
        vo.setContactName(adminUserDO.getNickname());
        vo.setDomain("");
        vo.setName(shopAuthDO.getShopName());
        vo.setStatus(0);
        vo.setUserId(adminUserDO.getId());
        vo.setPackageId(111L);
        vo.setExpireTime(LocalDateTimeUtil.parse("2030-01-01T12:00:00"));

        return vo;
    }

    default TenantDetailCreateReqVO convertTenantDetailCreate(MemberShopAuthDO shopAuthDO, AdminUserDO adminUserDO){
        TenantDetailCreateReqVO vo = new TenantDetailCreateReqVO();

        vo.setAddress(shopAuthDO.getAddress());
        vo.setAreaId(Long.valueOf(shopAuthDO.getAreaId()));
        vo.setDescription(shopAuthDO.getDescription());
        vo.setMobile(adminUserDO.getMobile());
        vo.setName(shopAuthDO.getShopName());
        vo.setPicUrl(shopAuthDO.getPicUrl());
        vo.setTitleUrl(shopAuthDO.getTitleUrl());
        vo.setUserId(adminUserDO.getId());
        vo.setSize(shopAuthDO.getSize());
        vo.setRoomCount(shopAuthDO.getRoomCount());
        vo.setJiushiCount(shopAuthDO.getJiushiCount());
        vo.setVideoUrl(shopAuthDO.getVideoUrl());


        return vo;
    }
}
